home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / Examples / USBModem / ModemStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-10  |  7.6 KB  |  270 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ModemStub.c
  3.  
  4.     Contains:    Shell for the USB Modem driver
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Errors.h>
  13.  
  14. #include "Modem.h"
  15. #include "ModemStub.h"
  16. #include "ModemDriver.h"
  17. #include "ShimSerialStub.h"
  18. #include "ShimSerialHAL.h"
  19.  
  20. //------------------------------------------------------
  21. //
  22. // Globals
  23. //
  24. //------------------------------------------------------
  25.  
  26. ShimSerialGlobals*    gGlobals;
  27.  
  28. //------------------------------------------------------
  29. //
  30. //    This is the driver description structure that the expert looks for first.
  31. //  If it's here, the information within is used to match the driver
  32. //  to the device whose descriptor was passed to the expert.
  33. //    Information in this block is also used by the expert when an
  34. //  entry is created in the Name Registry.
  35. //
  36. //------------------------------------------------------
  37.  
  38. USBDriverDescription    TheUSBDriverDescription = 
  39. {
  40.     // Signature info
  41.     kTheUSBDriverDescriptionSignature,
  42.     kInitialUSBDriverDescriptor,
  43.     
  44.     // Device Info
  45.     kUSBVendor,                             // vendor ID
  46.     kUSBProduct,                            // product ID
  47.     0,                                        // version of product = not device specific
  48.     0,                                        // protocol = not device specific
  49.     
  50.     // Interface Info            
  51.     0,                                        // Configuration Value
  52.     0,                                        // Interface Number
  53.     255,                                    // Interface Class
  54.     255,                                     // Interface SubClass
  55.     255,                                    // Interface Protocol    
  56.     
  57.     // Driver Info
  58.     kModemName,                                // Driver name for Name Registry
  59.     0,                                        // Device Class
  60.     0,                                        // Device Subclass 
  61.     0x1, 0x0, alphaStage, 0x1,                // version of driver = 1.0a1
  62.     
  63.     // Driver Loading Info
  64.     kUSBDoNotMatchGenericDevice                // Flags 
  65. };
  66.     
  67. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  68. {
  69.     kClassDriverPluginVersion,                // Version of this structure
  70.     modemDriverValidateHW,                    // Hardware Validation Procedure
  71.     modemDriverInitialize,                    // Initialization Procedure
  72.     modemDriverInitInterface,                // Interface Initialization Procedure
  73.     modemDriverFinalize,                    // Finalization Procedure
  74.     modemDriverNotifyProc,
  75. };
  76.  
  77. CFragConnectionID    ConnID;                    // Need to remember this
  78.  
  79. /***********************************************************************************/
  80. //    Function:        modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  81. //    Description:    Called upon load by Expert
  82. //
  83. //    Input:            Device reference, Device descriptor
  84. //    Output:            noErr
  85. /***********************************************************************************/
  86.  
  87. static OSStatus modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  88. {
  89.  
  90.     TraceMessage(0,"\pmodemDriverValidateHW");
  91.     device = 0;
  92.     desc = 0;
  93.     return noErr;
  94. }
  95.  
  96. /***********************************************************************************/
  97. //    Function:        OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc,
  98. //                                                                         UInt32 busPowerAvailable)
  99. //    Description:    Called upon load by Expert
  100. //
  101. //    Input:            Device reference, Device descriptor, bus power available
  102. //    Output:            result
  103. /***********************************************************************************/
  104.  
  105. static OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  106. {
  107. #pragma unused (busPowerAvailable)
  108.     
  109.     TraceMessage(0,"\pmodemDriverInitialize");
  110.     
  111.     gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  112.     if (gGlobals == NULL)
  113.         goto bail;
  114.  
  115.     if (pDesc->vendor != USBToHostWord(kUSBVendor))
  116.     {
  117.         StatusMessage(0, "\pClass - Not my device!", 0);
  118.         goto bail;
  119.     }
  120.     
  121.     USBExpertStatus(0, "\pModem driver loading as Class", 0);
  122.     
  123.     modemDriverEntry(device, pDesc);
  124.  
  125.     //    Install Device Control Entry for both the ".In" and ".Out functions that are
  126.     //    requied for a serial driver which is what we are.
  127.     if (noErr != InstallShimDrvr(ConnID))
  128.     {
  129.         StatusMessage(0, "\pCan't install DCEs!", 0);
  130.         goto bail;
  131.     }
  132.  
  133.     return noErr;
  134.  
  135. bail:
  136.     if (gGlobals)
  137.         PoolDeallocate(gGlobals);
  138.     gGlobals = NULL;
  139.     
  140.     return openErr;
  141. }
  142.  
  143. /***********************************************************************************/
  144. //    Function:        modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, 
  145. //                                                    USBDeviceDescriptor    *deviceDesc, USBDeviceRef device)
  146. //    Description:    Called to initialize driver for an individual interface - 
  147. //                    either by expert or internally by driver
  148. //
  149. //    Input:            Interface number, Interface descriptor, Device Descriptor, Device Reference
  150. //    Output:            result
  151. /***********************************************************************************/
  152.  
  153. static OSStatus modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
  154. {
  155. #pragma unused (interfaceNum)
  156. #pragma unused (interfaceDesc)
  157.  
  158.     TraceMessage(0,"\pmodemDriverInitInterface");
  159.  
  160.     if (gGlobals == NULL)
  161.         gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  162.  
  163.     if (gGlobals == NULL)
  164.         goto bail;
  165.  
  166.     if (deviceDesc->vendor != USBToHostWord(kUSBVendor))
  167.     {
  168.         StatusMessage(0, "\pInterface - Not my device!", 0);
  169.         goto bail;
  170.     }
  171.     
  172.     USBExpertStatus(0, "\pModem driver loading as Interface", 0);
  173.     
  174.     modemDriverEntry(device, deviceDesc);
  175.  
  176.     //    Install Device Control Entry for both the ".In" and ".Out functions that are
  177.     //    requied for a serial driver which is what we are.
  178.     if (noErr != InstallShimDrvr(ConnID))
  179.     {
  180.         StatusMessage(0, "\pCan't install DCEs!", 0);
  181.         goto bail;
  182.     }
  183.         
  184.     return noErr;
  185.  
  186. bail:
  187.     if (gGlobals)
  188.         PoolDeallocate(gGlobals);
  189.     gGlobals = NULL;
  190.     
  191.     return openErr;
  192. }
  193.  
  194. /***********************************************************************************/
  195. //    Function:        modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
  196. //    Description:    Called by Expert when driver is being shut down
  197. //
  198. //    Input:            Device reference, Device descriptor
  199. //    Output:            noErr
  200. /***********************************************************************************/
  201.  
  202. static OSStatus modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
  203. {
  204.     
  205.     TraceMessage(0,"\pmodemDriverFinalize");
  206.  
  207.     device = 0;
  208.     pDesc = 0;
  209.     
  210.     KillUSBIO();
  211.     RemoveShimDrvr(true);                            // force close - let the shim handle it
  212.  
  213.     if (gGlobals)
  214.         PoolDeallocate(gGlobals);
  215.         
  216.     gGlobals = NULL;
  217.     
  218.     return noErr;
  219. }
  220.  
  221. /***********************************************************************************/
  222. //    Function:        ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
  223. //    Description:    
  224. //
  225. //    Input:            Notification proc pointer
  226. //    Output:            noErr
  227. /***********************************************************************************/
  228.  
  229. static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
  230. {
  231.     pExpertNotify = 0;
  232.     return noErr;
  233. }
  234.  
  235. /***********************************************************************************/
  236. //    Function:        modemDriverNotifyProc(UInt32 notification, void *pointer)
  237. //    Description:    
  238. //
  239. //    Input:            Notification and pointer
  240. //    Output:            result
  241. /***********************************************************************************/
  242.  
  243. static OSStatus    modemDriverNotifyProc(UInt32 notification, void *pointer, UInt32 refCon)
  244. {
  245. #pragma unused (notification, pointer)
  246.     OSStatus err = noErr;
  247.     
  248.     TraceMessage(0,"\pmodemDriverNotifyProc");
  249.     
  250.     return err;
  251. }
  252.  
  253. /***********************************************************************************/
  254. //    Function:        InitDriver(CFragInitBlock *init)
  255. //    Description:    This routine saves our connection id
  256. //
  257. //    Input:            init (unused)
  258. //    Output:            noErr
  259. /***********************************************************************************/
  260.  
  261. OSErr InitDriver(CFragInitBlock *init)
  262. {
  263.     OSErr    err = noErr;
  264.     
  265.     TraceMessage(0, "\pEntering initDriver");
  266.     
  267.     ConnID = init->connectionID;
  268.  
  269.     return err;
  270. }